<?php
/**
	Classes: order_cart (myDbTb)
*/

/* This class serves to make some database operations with the order cart,
 * that is, the list of items that are at the order
 */
class order_cart extends myDbTb {
	public $order_id;
	public $items=array();	// Cart products
	public $price;

	// It inserts the order items to the orders_items database table
	function db_insert_deprecated() {
		foreach ($this->items as $item) {
			$item->db_insert();
		}
	}
	// It deletes the order items from the orders_items database table
	function db_delete() {
		$sql="DELETE FROM ".
		TABLE_ORDERS_PRODUCTS .
		" WHERE order_id=" . $this->id;
		return $this->sql_request($sql);
	}
	// It generates the list of items as order_items and loads them from the database
	function db_load()  {
		global $server;
		$sql = "SELECT op.* FROM " .
				TABLE_ORDERS_PRODUCTS . " op " .
				" where op.order_id = ".$this->order_id;

		$result = $server->db->link->query($sql);
		$load_check = ($result->num_rows > 0);
		if ($load_check) {
			while ($row = $result->fetch_assoc()) {
				$order_item= new order_item();
				$order_item->set_from_array($row);
				array_push($this->items,$order_item);
			}
			return $load_check;
		}
	}
}
?>
